<?php
//$intOrderHeaderID = 18;
if (defined("SITE")){
	$strSite = SITE;
	//$strSite.sprintf("%08d",$intOrderHeaderID)
}
include (MODULE_SHOP_HOST . "/navigation/EmailHeader");
include (MODULE . "/action/qrySelectOrderHeader");
$intOrderCarriage = $myrow["Freight"];
unset($intTotal);
//STYLE='table-layout: fixed'
echo  "<link REL=stylesheet HREF='http://$SERVER_NAME/shop.css'>
	<table width='600' height='1000' align='center' class='Normal' border='0'  bgcolor='White'>
	<tr align='left' valign='top'>
		<td colspan='6'  width='600' height='100'><img src='http://".$SERVER_NAME."/images".SITE_SUFFIX."/EmailHeader.jpg' width='600' align='top' border='0'/></td>
	</tr>

	<tr>
		<td colspan='6' align='center'  height='70'>
			<h1 class='orderheading'>Receipt</h1>
		</td>
	</tr>
	<tr>
		<td colspan='3' align='left' class='Normal' height='40'>
			<b>Order Number:</b> ".$strSite.sprintf("%08d",$intOrderHeaderID)."
		</td>
		<td colspan='3' align='right'  height='40'>
			<b>Invoice/Tax Date:</b> ".ReformatFromMySqlDate($myrow["InvoiceDate"])."
		</td>
	</tr>
	
	<tr>
		<td colspan='3' align='left' class='Normal' height='40'>
			&nbsp;
		</td>
		<td colspan='3' align='right'  height='40'>
			<b>Dispatch Date:</b> ".ReformatFromMySqlDate($myrow["ShippedDate"])."
		</td>
	</tr>
	
	<tr>
		<td colspan='3' valign='top'  height='170'>
			<br/><b>Invoice to:</b>
			<br/>".$myrow["ShipName"]."
			<br/>".$myrow["ShipAddress"];

				if ($myrow["ShipAddress2"]){
					echo "<br/>".$myrow["ShipAddress2"];
				}
		
echo "
			<br/>".$myrow["ShipCity"]."
			<br/>".$myrow["ShipRegion"]."
			<br/>".$myrow["ShipPostalCode"]."
		</td>

		<td colspan='3' valign='top'>
			<br/><b>Deliver to:</b>
			<br/>".$myrow["DeliveryName"]."
			<br/>".$myrow["DeliveryAddress"];

				if ($myrow["DeliveryAddress2"]){
					echo "<br/>".$myrow["DeliveryAddress2"];
				}
		
echo "
			<br/>".$myrow["DeliveryCity"]."
			<br/>".$myrow["DeliveryRegion"]."
			<br/>".$myrow["DeliveryPostalCode"]."
		</td>
	</tr>
	
	<tr>
		<td colspan='6' align='left'  height='20'>
";
			if(EXTRA_ORDER_FIELD){
				echo "<br/><b>".EXTRA_ORDER_FIELD."</b>".$myrow["OtherInfo"]."<br/>";
			}
echo "
		</td>
	</tr>
	
	<tr align='center' height='20'>
        <td align='left' width='230'><b>Product</b></td>
		<td align='center' width='30'><b>qty</b></td>
		<td align='center' width='60'><b>Unit Price ".CURRENCY."</b></td>
		<td align='center' width='90'><b>Net Price ".CURRENCY."</b></td>
		<td align='center' width='80'><b>VAT ".CURRENCY."</b></td>
		<td align='right' width='120'><b>Total ".CURRENCY."</b></td>
    </tr>";
	
	include (MODULE . "/action/qrySelectOrderDetails$SHOP_TYPE");
	do{
		echo "<tr align='right' bgcolor=\"".switch_background($boBG)."\">
	 		<td align='left' height='15'>";
			
					if ($myrow["QuantityPerUnit"]>1){
						echo $myrow["QuantityPerUnit"]."&nbsp;";
					}
					
				echo "<span class='Small'>".$myrow["Product"];
					if($myrow["Colour"]){
						echo "&nbsp; Colour: ".$myrow["Colour"];
					}
								
					if($myrow["Size"]){
						echo "&nbsp;Size: ".$myrow["Size"];
					}
				echo "</span>
			</td>
			<td>".$myrow["Quantity"]."</td>
			<td>".number_format($myrow["NetPrice"], 2, '.', '')."</td>
	        <td>".number_format($myrow["NetTotal"], 2, '.', '')."</td>
	        <td>".number_format($myrow["VatPayable"], 2, '.', '')."</td>
			<td>".number_format($myrow["Amount"], 2, '.', '')."</td>
	    </tr>";
		$boBG = -1 - $boBG; //alternate $boBG values from -1 and 0
		$intTotal = number_format($intTotal + $myrow["Amount"], 2, '.', '');
		$intVatPayableTotal = number_format($intVatPayableTotal + $myrow["VatPayable"], 2, '.', '');
		$intNetTotalTotal = number_format($intNetTotalTotal + $myrow["NetTotal"], 2, '.', '');
		$intVATRate = $myrow["VatRate"];
	} while ($myrow = mysql_fetch_array($result));
	
	
    echo "<tr>
        <td colspan='3' align='left'  height='20'>Carriage</td>";
		
		
			if ($intOrderCarriage !== "0.00"){
					if($SHOP_TYPE == "Trade"){
						$intNetCarriage = number_format($intOrderCarriage, 2, '.', '');
						$intVATCarriage = number_format(($intOrderCarriage * ($intVATRate/100)), 2, '.', '');
						$intTotalCarriage = number_format(($intOrderCarriage + $intVATCarriage), 2, '.', '');
						$intTotal = $intTotal + $intTotalCarriage;
					}else{
						$intNetCarriage = number_format($intOrderCarriage / (($intVATRate/100)+1), 2, '.', '');
						$intVATCarriage = number_format(($intOrderCarriage - ($intOrderCarriage / (($intVATRate/100)+1))), 2, '.', '');
						$intTotalCarriage = number_format($intOrderCarriage, 2, '.', '');
						$intTotal = $intTotal + $intTotalCarriage;
					}
					
				echo "	
				<td align='right'>".$intNetCarriage."</td>
				<td align='right'>$intVATCarriage</td>
				<td align='right'>".number_format($intTotalCarriage, 2, '.', '')."</td>";
			}else{
				$intNetCarriage = '0';
				$intVATCarriage = '0';
				 echo "<td colspan='5' align='right' class='Small'>Included</td>";
			}
		
	
	echo "
		</td>
    </tr>
	
	<tr>
 		<td colspan='3'  height='20'>Total</td>
		<td align='right'><b>".CURRENCY.number_format($intNetTotalTotal + $intNetCarriage, 2, '.', '')."</b></td>
		<td align='right'><b>".CURRENCY.number_format($intVatPayableTotal + $intVATCarriage, 2, '.', '')."</b></td>
		<td align='right'><b>".CURRENCY.number_format($intTotal, 2, '.', '')."</b></td>
    </tr>";
	
	if(RECEIPT_MESSAGE){
		echo "
		<tr valign='bottom'>
	 		<td colspan='6' align='center' class='Normal'>
				".RECEIPT_MESSAGE."
			</td>
	    </tr>
		";
	}
	
echo "
	<tr valign='bottom'>
 		<td colspan='6' align='center' class='small'>
			".COMPANY_REGISTERED_ADDRESS."&nbsp;".VAT_NUMBER."
		</td>
    </tr>
	
</table>";

?>